/****************************************************************************
 *
 *  CHUNK3DS.H
 *
 *  (C) Copyright 1997 by Autodesk, Inc.
 *
 *  This program is copyrighted by Autodesk, Inc. and is licensed to you under
 *  the following conditions.  You may not distribute or publish the source
 *  code of this program in any form.  You may incorporate this code in object
 *  form in derivative works provided such derivative works are (i.) are de-
 *  signed and intended to work solely with Autodesk, Inc. products, and (ii.)
 *  contain Autodesk's copyright notice "(C) Copyright 1995 by Autodesk, Inc."
 *
 *  AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  AUTODESK SPE-
 *  CIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
 *  A PARTICULAR USE.  AUTODESK, INC.  DOES NOT WARRANT THAT THE OPERATION OF
 *  THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
 *
 ***************************************************************************/

#ifndef CHUNK_3DS_H
#define CHUNK_3DS_H

#include "3DSTYPE.H"
#include "3DSERR.H"
#include "CHUNKINF.H"

/* Private Typedefs */

/* chunk3ds - Internal database representation of file information */
typedef struct chunk3ds {
   chunktag3ds tag;           /* Type of chunk */
   ulong3ds     size;         /* Number of bytes used by chunk */
   ulong3ds     position;     /* Offset in source file */
   void        *data;         /* Memory copy of file data */
   struct chunk3ds *sibling;  /* Next chunk in database */
   struct chunk3ds *children; /* Chunks contained within this chunk */
   ubyte3ds readindex;        /* Index of source file in file table */
   ubyte3ds writeindex;       /* Index of destination file in file table */
} chunk3ds;

/* chunklistentry3ds - Cross reference between name and chunk */
typedef struct {
   char3ds *name;                  /* Chunk Name list */
   chunk3ds *chunk;                /* Corresponding Pos */
} chunklistentry3ds;

/* chunklist3ds - List of cross references */
typedef struct 
{
   ulong3ds count; /* Number of entries in list */
   chunklistentry3ds *list; /* Contents of list */
} chunklist3ds;

/* End Private */

/* Public Typedefs */

/* namelistentry3ds - Name of database object */
typedef struct 
{
   char3ds *name; /* Name of object */
} namelistentry3ds;

/* namelist3ds - List of database object names */
typedef struct
{
   ulong3ds count;          /*--- How many entries are in list */
   ulong3ds spaces;         /*--- How much space for entries */
   namelistentry3ds *list;  /*--- char ** to access pointers */
} namelist3ds;

/* End Public */

/* Public Prototypes */

/* Functions to use with namelist3ds structures */
void InitNameList3ds(namelist3ds **chunk, ulong3ds count);
void ReleaseNameList3ds(namelist3ds **chunk);
void AddToNameList3ds(namelist3ds **list, char3ds *name);
/* End Public */

void InitChunk3ds(chunk3ds **chunk);
void InitChunkAs3ds(chunk3ds **chunk, chunktag3ds tag);
void *InitChunkAndData3ds(chunk3ds **chunk, chunktag3ds tag);
void ReleaseChunk3ds(chunk3ds **chunk);
void ReleaseSiblingChunk3ds(chunk3ds **chunk);
void DeleteChunk3ds(chunk3ds *chunk);
void FindChunk3ds(chunk3ds *local, chunktag3ds tag, chunk3ds **chunk);
void FindNextChunk3ds(chunk3ds *local, chunktag3ds tag, chunk3ds **chunk);
void AddChild3ds(chunk3ds *parent, chunk3ds *child);
void ReplaceOrAddChild3ds(chunk3ds *parent, chunktag3ds tag, chunk3ds **child);
void CopyChunk3ds(chunk3ds *ichunk, chunk3ds **ochunk);
void DisconnectChunk3ds(chunk3ds *chunk);
void CopyChunkData3ds(chunk3ds *ichunk, chunk3ds *ochunk);
void InitChunkList3ds(chunklist3ds **chunk, ulong3ds count);
void ReleaseChunkList3ds(chunklist3ds **chunk);
void *InitChunkData3ds(chunk3ds *chunk);
void *ReadChunkData3ds(chunk3ds *chunk);
void WriteChunkData3ds(chunk3ds *chunk);
void FreeFileChunkData3ds(chunk3ds *chunk);
void FreeChunkData3ds(chunk3ds *chunk);
long3ds CheckChunk3ds(chunk3ds *chunk);
long3ds GetChunkValue3ds(chunktag3ds tag);
void AddChildOrdered3ds(chunk3ds *parent, chunk3ds *child);


#endif
